<!-- 新增收获 -->
<template>
  <el-dialog :title="dialog.title" :visible.sync="dialog.show" width="530px" custom-class="mydialog" append-to-body @close="handleClose">
    <div class="dialog-content">
      <el-form ref="form1" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="出货仓：" >
          {{ modalData.allocation.depotOut }}
        </el-form-item>
        <el-form-item label="SKU名称：" >
          {{ modalData.allocation.skuName }}
        </el-form-item>
        <el-form-item label="收货数量：" >
          <el-input v-model="form.receiveAmount" placeholer="" type="number"/>
        </el-form-item>
      </el-form>
      <div class="text-center mt-30">
        <el-button :disabled="isConfirmDisabled" class="greenbt  bt-wd" type="primary" @click="confirm">确定收货</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { allocationReceive } from '@/api/pas/allocation'
export default{

  props: {
    // 父组件调用时传进来的参数
    modalData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      dialog: {
        title: '', show: true
      },
      form: {
        number: ''
        // ,receiveAmount:1
      },
      rules: {},
      isConfirmDisabled: false
    }
  },
  methods: {
    handleClose() {
      this.$emit('close')
    },
    confirm() {
      this.isConfirmDisabled = true
      if (this.form.receiveAmount && parseInt(this.form.receiveAmount) > 0) {
        if (this.modalData.allocation.allocationId && this.modalData.allocation.allocationId > 0) {
          var data = { 'allocationId': this.modalData.allocation.allocationId, 'receiveAmount': this.form.receiveAmount }

          console.log(1)

          if ((parseInt(this.form.receiveAmount) + this.modalData.allocation.receiveAmount) > this.modalData.allocation.allocationAmount) {
            this.$message({
              message: '收货数量不能大于调拨数量',
              type: 'warning'
            })
            this.isConfirmDisabled = false
            return
          }

          allocationReceive(data).then((res) => {
            if (res.data && res.data.status === 'success') {
              this.$message({
                message: '收货成功',
                type: 'warning'
              })
              this.modalData.shutDownModelAndRefresh()
            }
            this.isConfirmDisabled = false
          })
        } else {
          this.$message({
            message: '数据异常,请刷新重试',
            type: 'warning'
          })
          this.isConfirmDisabled = false
        }
      } else {
        this.$message({
          message: '请输入收货数量',
          type: 'warning'
        })
        this.isConfirmDisabled = false
      }
    }
  }
}
</script>
